
BINUTILS_HOME := /mnt/soft/bbb

CC := gcc
# CFLAGS := -std=gnu99 -g -I$(BINUTILS_HOME)/include -I`pwd`
# LDFLAGS += -L$(BINUTILS_HOME)/lib64 -lbfd  -liberty -ldl -lc -lz 
CFLAGS := -std=gnu99 -g 
LDFLAGS += -lbfd  -liberty -ldl -lc -lz -lopcodes

test: patch-elf-bfd patch-elf-bfd.a
	# strip patch-elf-bfd
	./patch-elf-bfd patch-elf-bfd rd --func main 31
	# ./patch-elf-bfd vcs1 --func main 8d4c240483e4f0ff --addr 0x92f3610 8d4c240483e4f0ff --key 8d4c240483e4f0ff71fc558d410489e556535189cee8b7814c0081c332c1f607 00
	# ./patch-elf-bfd vcs1 --func main 8d4c240483e4f0ff --addr 0x92f3610 8d4c240483e4f0ff
	# ./patch-elf-bfd patch-elf-bfd --func main 8d4c240483e4f0ff --key 5548....4883ec30 ab
	# ./patch-elf-bfd patch-elf-bfd --func main 8d4c240483e4f0ff --key 5548 ab
	# ./patch-elf-bfd patch-elf-bfd.a w --func main 3333 --addr 7ed 3333

	# objdump -d patch-elf-bfd.a > patch-elf-bfd.a.1.asm

patch-elf-bfd: patch-elf-bfd.o parse_elf_bfd.o elf-dis.o
	$(CC) $^  $(CFLAGS) $(LDFLAGS) -o $@

patch-elf-bfd.a: patch-elf-bfd.o parse_elf_bfd.o
	$(AR) -rc $@ $^
	objdump -d $@ > $@.asm

%.o: %.c
	$(CC) $(CFLAGS) -c $^ -o $@
# test:  all
# 	./main
# 	objdump -d main > main.asm

# all:
# 	# gcc -Wl,-Bdynamic main.c -Wl,-Bstatic -lbfd  -liberty -Wl,-Bdynamic -ldl -lc -lz -o main
# 	# gcc  -g main.c -lbfd  -liberty -ldl -lc -lz -o main
# 	gcc $(CFLAGS) main.c -lbfd  -liberty -ldl -lc -lz -o main
# 	gcc $(CFLAGS) -c main.c -o main.o
# 	ar -rc main.a main.o
# 	objdump -d main > main.asm
# 	# cp main main.elf
# 	# ./main
clean:
	rm *.o patch-elf-bfd *.asm *.a
